<?php
global $_GPC, $_W;
$GLOBALS['frames'] = $this->getMainMenu();
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
load()->func('tpl');
$pageindex = max(1, intval($_GPC['page']));
$pagesize=10;
$where=' WHERE  uniacid=:uniacid and cus_id=:cus_id ';
$data[':uniacid']=$_W['uniacid'];
$data[':cus_id']=$_GPC['cus_id'];
if($_GPC['time']){
    $start=strtotime($_GPC['time']['start']);
    $end=strtotime($_GPC['time']['end']);
    $where.=" and timesjc >={$start} and timesjc<={$end}";
}
if(isset($_GPC['keywords'])){
    $where.="  and (ordernum LIKE  concat('%', :name,'%') or uname LIKE  concat('%', :name,'%') or phone LIKE  concat('%', :name,'%'))";
    $data[':name']=$_GPC['keywords']; 
}
if($_GPC['type']){
  if ($_GPC['state']) {
  	$where.=" and type={$_GPC['type']} and state={$_GPC['state']}";
	$active=$_GPC['type'];
	$activef=$_GPC['state'];
  }else{
  	$where.=" and type={$_GPC['type']}";
	$active=$_GPC['type'];
  }
}else{
  if ($_GPC['state']) {
  	$where.=" and state={$_GPC['state']}";
	$active=0;
	$activef=$_GPC['state'];
  }
}
	$sql="SELECT * FROM ".tablename('zh_gjw_orders') .$where." ORDER BY time desc";
	$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_gjw_orders').$where." ORDER BY time desc",$data);

$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
$orders=pdo_fetchall($select_sql,$data);
$pager = pagination($total, $pageindex, $pagesize);

if($operation=='delete'){
	$res=pdo_delete('zh_gjw_orders',array('id'=>$_GPC['id']));
	// var_dump($res);die;
	if($res){
		pdo_delete('zh_gjw_orderassess',array('p_id'=>$_GPC['id']));
	  	message('删除成功',$this->createWebUrl('cussellorders',array()),'success');
	}else{
	  message('删除失败','','error');
	}
}
if($_GPC['op']=='three'){
	$now=strtotime('now');
	$end=strtotime("+10 days");
	$res=pdo_update('zh_gjw_orders',array('stime'=>$now,'etime'=>$end,'state'=>3),array('id'=>$_GPC['id']));
	if($res){
     message('', 'referer', 'success');
    }else{
          message('失败！','referer','error');
    }
}
include $this->template('web/cussellorders');